1 /*
2 Copyright: Marcelo S. N. Mancini (Hipreme|MrcSnm), 2018 - 2021
3 License:   [https://creativecommons.org/licenses/by/4.0/|CC BY-4.0 License].
4 Authors: Marcelo S. N. Mancini
5 
6 	Copyright Marcelo S. N. Mancini 2018 - 2021.
7 Distributed under the CC BY-4.0 License.
8    (See accompanying file LICENSE.txt or copy at
9 	https://creativecommons.org/licenses/by/4.0/
10 */
11 module hip.debugging.runtime;
12 import std.traits : isFunction;
13 
14 /**
15 * UDA used together with runtime debugger, it won't print if it has this attribute
16 */
17 struct Hidden;
18 
19 /**
20 * UDA used together with runtime debugger, mark your class member for being able to change
21 * the target property on the runtime console
22 */
23 struct RuntimeConsole;
24 
25 
26 /**
27 * Each time a variable is registered, it goes in there for being able to runtime cast it
28 */
29 private string[] REGISTERED_TYPES;
30 
31 struct RuntimeVariable
32 {
33     void* var;
34     string name;
35     string type;
36 }
37 
38 
39 class RuntimeDebug
40 {
41     /**
42     * Prints every member from a class instance
43     */
44     public static void instancePrint(alias instance)(const ref typeof(instance) cls = instance)
45     {
46         version(HIPREME_DEBUG)
47         {
48             import std.stdio:writefln;
49             alias T = typeof(instance);
50             MEMBERS: foreach(member; __traits(allMembers, T))
51             {
52                 //Guards against potential erros like getting private members
53                 static if(__traits(compiles, __traits(getMember, T, member)))
54                 {
55                     enum name = "cls."~member;
56                     foreach(attr; __traits(getAttributes, mixin("T."~member)))
57                     {
58                         static if(is(attr == Hidden))
59                             continue MEMBERS;
60                     }
61                     static if(!mixin("isFunction!("~cls.stringof~"."~member~")") && member != "Monitor")
62                     {
63                         mixin("writefln(\""~instance.stringof~"."~member~": %s\", mixin(name));");
64                     }
65                 }
66             }
67         }
68     }
69 
70     public static void attachVar(alias varSymbol)(const ref typeof(varSymbol) var = varSymbol)
71     {
72         version(HIPREME_DEBUG)
73         {
74             alias T = typeof(varSymbol);
75             static if(is(T == class))
76             {
77                 static foreach(member; __traits(allMembers, T))
78                 {
79                     static if(__traits(compiles, __traits(getMember, T, member)))
80                     {
81                         foreach(attr; __traits(getAttributes, mixin("T."~member)))
82                         {
83                             static if(is(attr == RuntimeConsole))
84                             {
85                                 
86                                 break;
87                             }
88                         }
89                     }
90                 }
91             }
92             else
93             {
94 
95             }
96         }
97     }
98 
99     // public static alias[] variables;
100 }